package containers;

import java.util.concurrent.CopyOnWriteArrayList;

import util.CardValues;

import casino.Casino;
import casino.GameCard;
import casino.Player;


public class Hand extends CardContainer{
	 private static final int gap = 30;
	 private float offset;
	 
	 public Hand(Casino n, Player p, int x, int y, int w, CopyOnWriteArrayList<GameCard> c){
		 super(n,p,x,y,w,CardValues.height,c);
		 sort();
		 offset = (float)(width - (CardValues.width*cards.size() + gap*(cards.size()-1)))/2;
		 if(offset < 0){
			 offset = 0;
			 float rgap = (float)(width-(cards.size()*CardValues.width))/(cards.size()-1);
			 for(int i = 0; i < cards.size(); i++){
				 cards.get(i).setPosition((int)(x+i*(CardValues.width+rgap)+offset), y);
			 }
		 }else{
			 for(int i = 0; i < cards.size(); i++){
				 cards.get(i).setPosition((int)(x+i*(CardValues.width+gap)+offset), y);
			 }
		 }
	 }
	 
	 public Hand(Casino n, Player p, int x, int y, int w){
		 super(n,p,x,y,w,CardValues.height);
	 }
	 
	 public void lengthChange(){
		 sort();
		 for(int i = 0; i < cards.size(); i++){
			 if(!cards.get(i).faceUp){
				 cards.get(i).flip();
			 }
			 offset = (float)(width - (CardValues.width*cards.size() + gap*(cards.size()-1)))/2;
			 if(offset < 0){
				 offset = 0;
				 float rgap = (float)(width-(cards.size()*CardValues.width))/(cards.size()-1);
				 cards.get(i).setPosition((int)(x+i*(CardValues.width+rgap)+offset), y);
			 }else{
				 cards.get(i).setPosition((int)(x+i*(CardValues.width+gap)+offset), y);
			 }
			 casino.bringToFront(cards.get(i));
		 }
	 }
	 
	 public boolean containsValue(int v){
		 for(GameCard c: cards){
			 if(c.getValue() == c.getValue()){
				 return true;
			 }
		 }
		 return false;
	 }
	 
	 public void sort(){}
}
